#include "circle.hpp"
#include <limits>

std::istream &operator>>(std::istream &in, Circle &c)
{
    std::cout << "Please input centre and radius:" << std::endl;
    in >> c.p.x >> c.p.y;
loop:
    in >> c.r;
    if (in.fail())
    {
        in.clear();
        in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        std::cerr << "Illegal input!" << std::endl;
        goto loop;
    }
    if (c.r < 0)
    {
        std::cerr << "Illegal input!" << std::endl;
        goto loop;
    }
    return in;
};
Circle::Circle(double x, double y, double r) : p(x, y), r(r)
{
    std::cout << __FUNCTION__ << " called." << std::endl;
    system("pause");
}
Circle::~Circle()
{
    std::cout << __FUNCTION__ << " called." << std::endl;
    system("pause");
}

bool Circle::isCross(const Circle &c)
{
    double d = p.distance(c.p);
    return (std::abs(r - c.r) < d) && (d < r + c.r);
}